﻿using B.S.Database.Domain.Entity;
using B.S.Database.ErrorCode;
using B.S.Database.Interface.Interface;
using B.S.Database.Read.Api.Application.Commands.Slaughter;
using MediatR;

namespace B.S.Database.Read.Api.Application.CommandHandler.Slaughter
{
    public class SlaughterShowCommandHandler : IRequestHandler<SlaughterShowCommands, Apiresult<List<Slaughter_Information>>>
    {
        private readonly IBaseResotity<Slaughter_Information> slaughterRepo;

        public SlaughterShowCommandHandler(IBaseResotity<Slaughter_Information> SlaughterRepo)
        {
            slaughterRepo = SlaughterRepo;
        }
        public Task<Apiresult<List<Slaughter_Information>>> Handle(SlaughterShowCommands request, CancellationToken cancellationToken)
        {
            Apiresult<List<Slaughter_Information>> res = new Apiresult<List<Slaughter_Information>>();
            res.Code = ApiEnums.成功;
            res.Message = ApiEnums.成功.ToString();
            var list = slaughterRepo.GetAll().Where(c=>c.TraceabilityId ==request.TraceabilityId);
            res.Data = list.ToList();
            return Task.FromResult(res);
        }
    }
}
